package cn.gemframe.utils;

import java.io.IOException;
import java.io.OutputStream;

import cn.gemframe.config.office.GemFrameWordsLicense;
import com.aspose.cells.Workbook;
import com.aspose.slides.Presentation;


public class GemOfficeUtlis {

	public static boolean WordConVersion(OutputStream outputStream, com.aspose.words.Document document, int fileType) {
		boolean license = GemFrameWordsLicense.getLicense();
		if (license) {
			try {
				document.save(outputStream, fileType);
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (outputStream != null) {
					try {
						outputStream.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
			return true;
		} else {
			return false;
		}
	}

	public static boolean ExcelConVersion(OutputStream outputStream, Workbook workbook, int fileType) {
		boolean license = GemFrameWordsLicense.getLicense();
		if (license) {
			try {
				workbook.save(outputStream, fileType);
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (outputStream != null) {
					try {
						outputStream.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
			return true;
		} else {
			return false;
		}
	}

	public static boolean PPTConVersion(OutputStream outputStream, Presentation presentation, int fileType) {
		boolean license = GemFrameWordsLicense.getLicense();
		if (license) {
			try {
				presentation.save(outputStream, fileType);
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (outputStream != null) {
					try {
						outputStream.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
			return true;
		} else {
			return false;
		}
	}
}
